package com.xnewtech.xplatform.swan.libs.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.xnewtech.xplatform.swan.libs.mp.SwanCustomMetaObjectHandler;
import com.xnewtech.xplatform.swan.libs.mp.dbid.SwanDatabaseIdProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * MybatisPlus配置
 *
 * @author xnew
 * @Date 2017/5/20 21:58
 */
@Configuration
public class MybatisPluginConfig {

    /**
     * mybatis-plus分页插件
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }

    /**
     * 自定义公共字段自动注入
     */
    @Bean
    public MetaObjectHandler metaObjectHandler() {
        return new SwanCustomMetaObjectHandler();
    }

    /**
     * 乐观锁mybatis插件
     */
    @Bean
    public OptimisticLockerInterceptor optimisticLockerInterceptor() {
        return new OptimisticLockerInterceptor();
    }

    /**
     * 数据库id选择器
     */
    @Bean
    public SwanDatabaseIdProvider swanDatabaseIdProvider() {
        return new SwanDatabaseIdProvider();
    }

}
